var num = 1;                                                 //参数1
var app = angular.module("myApp",[]);

app.controller("myCtrl",function($scope,$http,getEducationImformation){
	getEducationImformation.initEducationImformation(1,function(response){
		$scope.arr = response.data.list;
	});
	
	//angular的监听事件
    window.addEventListener("scroll", function(event) {
    	var clientHeight = $(this).height();
    	var scrollTop = $(this).scrollTop();
    	var docHeight = $(document).height();
    	//判断是否到达底部，上拉加载
        if(clientHeight + scrollTop >= docHeight){
        	num++;
        	getEducationImformation.initEducationImformation(num,function(response){
        		if(num > response.data.pager.pageCount){
					return;
				}
				$scope.arr = $scope.arr.concat(response.data.list);
			});
	    }    
    });
})

//创建ng的工厂,请求商品的数据，进行依赖注入
app.factory("getEducationImformation",function($http){
	var obj = {};
	obj.initEducationImformation = function(x,_callback){
		var params = {
		    pageNum : x,
		    pageSize:10
		};
		params = $.param(params);
		$http({
	        method : "post",
	        dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
		    crossDomain: true,
		    headers:{'Content-Type': 'application/x-www-form-urlencoded'},
		    data: params,
	        async:true,
	        url : host + "/terminal/educationArcticles/infoArticle"
	   }).success(function(response){
	        if(response.code == 2000){
	        	_callback(response);
	        }
	    }).error(function(response){
	    	console.log(response);
	    });
	}
	return obj;
})
